package org.dromara.patrol.controller;

import lombok.RequiredArgsConstructor;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.patrol.domain.vo.PatrolTaskVo;
import org.dromara.patrol.domain.bo.PatrolTaskBo;
import org.dromara.patrol.service.IPatrolTaskService;

/**
 * 巡店管理-巡店任务（实时、现场、录像，不包含自检任务）配置
 * 前端访问路由地址为:/patrol/task
 *
 * @author Chan
 * @date 2024-03-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/task")
public class PatrolTaskController extends BaseController {

    private final IPatrolTaskService patrolTaskService;

    /**
     * 新增巡店管理-巡店任务（实时、现场、录像，不包含自检任务）配置
     */
    @SaCheckPermission("patrol:task:add")
    @Log(title = "巡店管理-巡店任务（实时、现场、录像，不包含自检任务）配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PatrolTaskBo bo) {
        return toAjax(patrolTaskService.insertByBo(bo));
    }

    /**
     * 根据任务类型查询最近一次任务信息 taskSubType=[字典表：PATROL_REALTIME 实时巡店，PATROL_LIVE 现场巡店，PATROL_VIDEO 录像巡店]
     * @param taskSubType
     * @return
     */
    @GetMapping("/lately")
    public R<PatrolTaskVo> getLatelyTaskInfo(@NotEmpty (message = "任务类型不能为空")
                                                 String taskSubType) {
        return R.ok(patrolTaskService.queryLatelyTaskInfo(taskSubType));
    }
}
